//当前项目安装 cnpm i mysql --save
//引入mysql库
let m = require('mysql')

//建立数据库连接对象
let conn = m.createConnection({
    host: 'localhost', user: 'admin', password: 'admin', port: 3306, database: 'mall'
})

//连接mysql server
conn.connect()

let sql = 'show databases';
//conn执行查询
conn.query(sql, function (err, result) {
    if (err) {
        console.log('[SELECT ERROR] - ', err.message)
        return
    }
    console.log('--------------------------SELECT----------------------------')
    for (let rs of result.values()) {
        console.log(rs.Database)
    }
    console.log('------------------------------------------------------------\n\n')
})

//关闭连接
conn.end();
